
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title id="divTitle">中医疾病信息编辑</title>
    <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />

    <style type="text/css">
        *, body {
            margin: 0px;
            font-family: '微软雅黑';
        }
    </style>
    <script th:src="@{/js/jquery-1.10.2.min.js}"></script>
    <script th:src="@{/js/jquery.form.js}"></script>
    <script th:src="@{/js/generic.js}"></script>
</head>

<body>


<table class="maintable">
    <tr>

        <td class="rightmaintd" valign="top">
            <div class="searchdiv">
                <a href="/zyjb">&lt; 返回</a>
                <div class="rightsearchdiv"><!-- name --></div>
            </div>
            <table class="leftrighttable" border="0">
                <tr>
                    <td class="lefttdtable" width="50%" valign="top">
                        <table cellpadding="6">
                            <tr>
                                <td class="tdname">中医疾病编号</td>
                                <td><input type="text" id="bianhao" class="textinput" maxlength="50" th:value="${zhengzhuang.getBianhao()}"></td>
                            </tr>
                            <tr>
                                <td class="tdname">疾病名称</td>
                                <td><input type="text" id="mingcheng" class="textinput" maxlength="50" th:value="${zhengzhuang.getMingcheng()}"></td>
                            </tr>
                            <tr>
                                <td class="tdname">疾病部位</td>
                                <td><input type="text" id="buwei" class="textinput" maxlength="50" th:value="${zhengzhuang.getBuwei()}"></td>
                            </tr>

                            <tr>
                                <td class="tdname">特征</td>
                                <td><input type="text" id="tezheng" class="textinput" maxlength="50" th:value="${zhengzhuang.getTezheng()}"></td>
                            </tr>
                            <tr>
                                <td class="tdname">病理</td>
                                <td><input type="text" id="bingli" class="textinput" maxlength="50" th:value="${zhengzhuang.getBingli()}"></td>
                            </tr>

                        </table>
                    </td>
                    <td class="righttdtable" width="50%" valign="top"></td>
                </tr>

            </table>
            <div class="shenhediv">
                <input type="button" value="保 &nbsp; &nbsp; 存" class="baocunbtn"  id="Sbutton">
                <span id="lrxx"></span>
                <span id="ID" th:text="${zhengzhuang.getId()}" class="shownone">ID</span>
            </div>

        </td>
    </tr>
</table>


</body>
</html>
<script type="text/javascript">
    var saveButton = document.getElementById('Sbutton');
    saveButton.addEventListener('click', ()=> {
        var ID=document.getElementById('ID').textContent;
        var bianhao= document.getElementById('bianhao').value;
        if(bianhao===""){
            alert("请输入疾病编号");
            return;
        }
        var mingcheng = document.getElementById('mingcheng').value;
        if(mingcheng===""){
            alert("请输入疾病名称");
            return;
        }
        /*判断疾病具体信息*/
        var buwei = document.getElementById('buwei').value;
        if(buwei==="")
            buwei=null;
        var tezheng = document.getElementById('tezheng').value;
        if(tezheng==="")
            tezheng=null;
        var bingli = document.getElementById('bingli').value;
        if(bingli==="")
            bingli=null;
            // 创建要发送的数据对象
        var data = {
            id: ID,
            bianhao: bianhao,
            mingcheng: mingcheng,
            buwei: buwei,
            tezheng: tezheng,
            bingli: bingli
        };
        // 发送 POST 请求
        var xhr = new XMLHttpRequest();
        xhr.open('PUT', '/zyjb/', true);
        xhr.setRequestHeader('Content-Type', 'application/json');
        xhr.onreadystatechange = function() {
            console.log(data);//测试用，可以删掉
            if (xhr.readyState === 4 && xhr.status === 200) {
                // 请求完成并成功处理后的回调函数
                console.log('数据已成功发送至后端');
                alert("保存成功！");
                window.location.href="/zyjb";
            }
        };
        xhr.send(JSON.stringify(data));
    });
</script>